﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="../demo.css" rel="stylesheet" type="text/css" />
<script src="../../scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	width: 100%;
	height: 100%;
	border: 0;
	margin: 0;
	padding: 0;
	overflow: visible;
}
</style>
</head>
<body>
	<div class="mini-toolbar" style="padding: 2px; border: 0;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 100%;"></td>
				<td style="white-space: nowrap;"><label
					style="font-family: Verdana;"> 推广下线时间: </label> <input
					id="paterdatebegin" class="mini-datepicker" format="yyyy-MM-dd HH"
					timeFormat="HH" showTime="true" />~<input id="paterdateend"
					class="mini-datepicker" format="yyyy-MM-dd HH" timeFormat="HH"
					showTime="true" /> <label style="font-family: Verdana;">
						注册时间: </label> <input id="datebegin" class="mini-datepicker"
					format="yyyy-MM-dd HH" timeFormat="HH" showTime="true" />~<input
					id="dateend" class="mini-datepicker" format="yyyy-MM-dd HH"
					timeFormat="HH" showTime="true" /> <label
					style="font-family: Verdana;">用户:</label> <input
					class="mini-textbox" id="key" /> <a class="mini-button"
					iconCls="icon-search" plain="true" onclick="search();">查询</a>
			</tr>
		</table>
	</div>
	<!--撑满页面-->
	<div class="mini-fit" style="height: 100px;">
		<div id="datagrid1" class="mini-datagrid"
			style="width: 100%; height: 100%;" url="/ios/pages/User/xialist.do"
			idField="id" sizeList="[5,10,20,50]" allowResize="true" pageSize="20"
			allowCellEdit="true" allowCellSelect="true" multiSelect="true"
			editNextOnEnterKey="true">
			<div property="columns">
				<div type="checkcolumn" style="width: 5px;"></div>
				<div type="indexcolumn" style="width: 5px;"></div>
				<div field="userid" width="120" headerAlign="center"
					allowSort="true">用户id</div>
				<div field="username" width="120" headerAlign="center"
					allowSort="true">用户昵称</div>
				<div field="extensionNumber" width="100" allowSort="true"
					renderer="onNumberRenderer">下线数</div>
				<div field="paterid" width="100" allowSort="true">我的上线</div>
			</div>
		</div>
	</div>

	<!-- 用户下线 -->
	<div id="UserWindow" class="mini-window" iconCls="icon-node" title="下线"
		style="width: 1350px; height: 550px; display: none;" showModal="true"
		allowResize="true" allowDrag="true">
		<input class="mini-hidden" name="id" id="download" /> <a
			class="mini-button" iconCls="icon-download" onclick="downloadData()"
			plain="true">数据下载</a> <label style="font-family: Verdana;">注册IP:
		</label> <label style="font-family: Verdana;" id="zcip"> </label>&nbsp;&nbsp;
		<label style="font-family: Verdana;"> 支付宝: </label> <label
			style="font-family: Verdana;" id="zfb"> </label>&nbsp;&nbsp; <label
			style="font-family: Verdana;"> 财付通: </label> <label
			style="font-family: Verdana;" id="cft"> </label>&nbsp;&nbsp; <label
			style="font-family: Verdana;"> QB: </label> <label
			style="font-family: Verdana;" id="qb"> </label>&nbsp;&nbsp; <label
			style="font-family: Verdana;"> 话费: </label> <label
			style="font-family: Verdana;" id="hf"> </label>&nbsp;&nbsp; <label
			style="font-family: Verdana;">兑换账户:</label> <input id="accountstr"
			class="mini-textbox" /> <a class="mini-button" iconCls="icon-search"
			plain="true" onclick="search1();">查询</a>
		</td>
		<div class="mini-fit">
			<div id="datagridUser" class="mini-datagrid"
				style="width: 100%; height: 100%;" borderStyle="border:0"
				showPageSize="false" allowAlternating="true" showPageIndex="false"
				sizeList="[5,10,20,50]" pageSize="20"
				url="/ios/pages/User/xialist.do">
				<div property="columns">
					<div type="indexcolumn" width="20"></div>
					<div field="userid" headerAlign="center" allowSort="true">用户ID</div>
					<div field="username" headerAlign="center" allowSort="true">用户昵称</div>
					<div field="register" headerAlign="center" allowSort="true">用户生成时间</div>
					<div field="integral" headerAlign="center" allowSort="true">用户总积分</div>
					<div field="huIntegral" allowSort="true" headerAlign="center">兑换积分</div>
					<div field="id" allowSort="true" renderer="onShengRenderer">剩余积分</div>
					<div field="IP" headerAlign="center" allowSort="true">注册IP</div>
					<div field="zfb1" headerAlign="center" allowSort="true">支付宝</div>
					<div field="cft1" headerAlign="center" allowSort="true">财付通</div>
					<div field="qq1" headerAlign="center" allowSort="true">QB</div>
					<div field="phone1" headerAlign="center" allowSort="true">话费</div>
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		var state = [ {
			id : 1,
			text : '不在线'
		}, {
			id : 2,
			text : '在线'
		} ];
		var addstate = [ {
			id : 0,
			text : '增加'
		}, {
			id : 1,
			text : '减少'
		} ];
		mini.parse();
		//var form = new mini.Form("#editform");
		//var editWindow = mini.get("#editWindow");
		var grid = mini.get("datagrid1");
		grid.load();

		var datagridUser = mini.get("datagridUser");
		var UserWindow = mini.get("UserWindow");

		mini.get("userid").allowInput = false;
		mini.get("username").allowInput = false;

		function onStateRenderer(e) {
			for (var i = 0, l = state.length; i < l; i++) {
				var g = state[i];
				if (g.id == e.value)
					return g.text;
			}
			return "";
		}

		function onNumberRenderer(e) {
			var record = e.record;
			var number = record.extensionNumber;//
			if (number == 0) {
				return 0;
			} else {
				return '<a class="New_Button" href="javascript:UserShow(\''
						+ record.id + '\');">' + e.value + '</a>';
			}
		}

		function UserShow(id) {
			mini.get("accountstr").setValue("");
			$.ajax({
				url : "/ios/pages/User/getId.do?id=" + id,
				success : function(text) {
					var o = mini.decode(text);
					document.getElementById('zcip').innerText = o.IP;
					document.getElementById('zfb').innerText = o.zfb1;
					document.getElementById('cft').innerText = o.cft1;
					document.getElementById('qb').innerText = o.qq1;
					document.getElementById('hf').innerText = o.phone1;
				},
				error : function() {
					alert("表单加载错误");
					form.unmask();
				}
			});
			datagridUser.load({
				paterid : id
			});
			UserWindow.show();
			mini.get("download").setValue(id);
		}

		function onHandleRenderer(e) {
			var grid = e.sender;
			var record = e.record;
			var id = record.id;
			var s = '';
			s = s
					+ '&nbsp;&nbsp;<a class="New_Button" href="javascript:editRow(\''
					+ id + '\');">增减积分</a>';
			return s;
		}

		function newRow() {
			form.clear();
			editWindow.show();
		}

		function search() {
			var datebegin = mini.get("datebegin").getFormValue();
			var dateend = mini.get("dateend").getFormValue();
			var paterdatebegin = mini.get("paterdatebegin").getFormValue();
			var paterdateend = mini.get("paterdateend").getFormValue();
			var key = mini.get("key").getValue();
			grid.load({
				userid : key,
				registerbegin : datebegin,
				registerend : dateend,
				paterdatebegin : paterdatebegin,
				paterdateend : paterdateend
			});
			grid.clearSelect();
		}

		function editRow(id) {
			editWindow.show();
			form.clear();
			form.loading();
			$.ajax({
				url : "/ios/pages/User/getId.do?id=" + id,
				success : function(text) {
					form.unmask();
					var o = mini.decode(text);
					form.setData(o);
					initprovince(o);
					mini.get("tableId").allowInput = false;
				},
				error : function() {
					alert("表单加载错误");
					form.unmask();
				}
			});
		}

		function cancelRow() {
			editWindow.hide();
		}

		function saveRow() {
			form.validate();
			if (form.isValid() == false)
				return;
			var data = form.getData();
			var json = mini.encode(data);
			form.loading();
			$.ajax({
				url : "/ios/pages/ObtainIntegral/save.do",
				type : "post",
				data : {
					submitData : json
				},
				success : function(text) {
					var o = mini.decode(text);
					if (o.state) {
						form.unmask();
						grid.load();
						editWindow.hide();
					} else {
						form.unmask();
						alert("保存出错了!");
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert("请求出错了!");
				}
			});
		}

		function reset() {
			form.clear();
		}

		function removeRow() {
			var rows = grid.getSelecteds();
			var ids = "";
			for (i = 0; i < rows.length; i++) {
				ids += "'" + rows[i].id + "',";
			}
			mini.confirm("确定删除记录？", "确定？", function(action, value) {
				if (action == "ok") {
					if (rows.length > 0) {
						var messageid = mini.loading("正在执行...", "wait");
						$.ajax({
							url : "/ios/pages/User/delete.do?id=" + ids,
							success : function(text) {
								var o = mini.decode(text);
								mini.hideMessageBox(messageid);
								if (o.state) {
									grid.load();
								} else {
									mini.alert("删除出错");
								}
							},
							error : function() {
								mini.hideMessageBox(messageid);
								mini.alert("删除出错");
							}
						});
					} else {
						return;
					}
				} else {
					return;
				}
			}, true);
		}

		function onShengRenderer(e) {
			var record = e.record;
			return record.integral - record.huIntegral;
		}

		function downloadData() {
			var paterid = mini.get("download").getValue();
			var url = "/ios/pages/User/exportData.do?paterid=" + paterid;
			window.location.href = url;
		}
		
		function search1() {
			var  accountstr = mini.get("accountstr").getValue();
			var paterid = mini.get("download").getValue();
			datagridUser.setUrl("/ios/pages/User/xialist.do?accountStr="+accountstr);
			datagridUser.load({
				paterid : paterid
			});
			
			datagridUser.clearSelect();
		}
	</script>
</body>
</html>